package com.liangtian.mdm.system.taskass.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.liangtian.mdm.base.controller.BaseController;
import com.liangtian.mdm.base.utils.ResultObject;
import com.liangtian.mdm.dm.common.pojo.ResponseMsg;
import com.liangtian.mdm.system.taskass.model.TaskAss;
import com.liangtian.mdm.system.taskass.service.TaskAssService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/taskAss")
public class TaskAssController extends BaseController {

    @Autowired
    private TaskAssService taskAssService;

    /**
     * 查询所有
     *
     * @param request
     * @param taskAss
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/queryAll", method = RequestMethod.POST)
    public String quertAll(HttpServletRequest request, TaskAss taskAss) {
        List<Map<String, Object>> returnLst = null;
        try {
            returnLst = taskAssService.selectTaskSurvey(taskAss);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return JSON.toJSONString(returnLst);
    }

    /**
     * 插入代理
     *
     * @param request
     * @param taskAss
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public JSONObject insert(HttpServletRequest request, TaskAss taskAss) {
        JSONObject jsonObject = new JSONObject();
        ResponseMsg<String> rMsg = new ResponseMsg<String>();
        try {
            taskAssService.insertTaskAss(taskAss);
            rMsg.setRspCode(0);
        } catch (Exception e) {
            e.printStackTrace();
            rMsg.setRspCode(-1);
        }
        jsonObject.put("rmsg", rMsg);
        return jsonObject;
    }

    /**
     * 插入代理
     *
     * @param request
     * @param taskAss
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/restAss", method = RequestMethod.POST)
    public ResultObject restAss(HttpServletRequest request, TaskAss taskAss) {
        try {
            taskAssService.restTaskAss(taskAss);
        } catch (Exception e) {
            e.printStackTrace();
        }
        ResultObject resultObject = new ResultObject(1, "", "");
        return resultObject;
    }
}
